﻿/*************************************************
作者: Plane
邮箱: 1785275942@qq.com
功能: 登录验证

           ~~获取更多教学资讯~~
//----------------*----------------\\
        教学官网：www.qiqiker.com
        官方微信服务号: qiqikertuts
        Plane老师微信: PlaneZhong
\\----------------*----------------//
*************************************************/

using PEProtocol;
using UnityEngine;
using UnityEngine.UI;

public class LoginWnd : WindowRoot {
    public InputField iptAcct;
    public Text zoneName;
    public Transform zoneRoot;

    protected override void InitWnd() {
        base.InitWnd();

        SetActive(zoneRoot, false);
        zoneName.text = "王者世界1086服";
        iptAcct.text = root.acctSys.account;
    }

    //TODO
    public void ClickChangeZone() {
        SetActive(zoneRoot);
    }
    public void ClickCloseBtn() {
        SetActive(zoneRoot, false);
    }
    public void ClickLoginBtn() {
        audioSvc.PlayUIAudio("loginBtnClick");

        if (string.IsNullOrEmpty(iptAcct.text)) {
            uiSvc.ShowTips("账号数据不合法");
        }
        else {
            root.acctSys.account = iptAcct.text;
            NetMsg req = new() {
                cmd = CMD.ReqAcctLogin,
                reqAcctLogin = new ReqAcctLogin {
                    acct = iptAcct.text,
                    pass = iptAcct.text,
                    dataID = 2001
                }
            };

            root.netSvc.SendMsg(req, (rsp) => {
                switch (rsp.errorCode) {
                    case ErrorCode.None:
                        uiSvc.ShowTips($"登录成功");
                        break;
                    case ErrorCode.acct_online_login:
                        uiSvc.ShowTips($"账号已登录Login。");
                        break;
                    case ErrorCode.acct_online_data:
                        uiSvc.ShowTips($"账号已登录Data");
                        break;
                    case ErrorCode.acct_l2d_offline:
                        uiSvc.ShowTips($"当前区服离线，请选择其大区。");
                        break;
                    default:
                        this.Error($"errorCode:{rsp.errorCode} 未处理。");
                        break;
                }
            });
        }
    }
}